import { sendCode, checkEmailCode, register, forgetPwd } from "@/Api/user";
import utils from "../utils";
const state = {};
const mutations = {};
const actions = {
  async sendCode({ commit }, data) {
    let result = await sendCode(data);
    console.log(result);
    if (result.data.status == 200) {
      return "success";
    } else {
      return "error";
    }
  },
  async register({ commit }, data) {
    let result = await checkEmailCode(data.email, data.code);
    if (result.data.status == 200) {
      let result = await register(data.email, data.password1);
      if (result.data.status == 200) {
        utils.setUser(data.email);
        return "success";
      } else {
        return "registerError";
      }
    } else {
      return "codeError";
    }
  },
  async updatePwd({ commit }, data) {
    let result = await checkEmailCode(data.email, data.code);
    if (result.data.status == 200) {
      let result = await forgetPwd(data.email, data.password1);
      if (result.data.status == 200) {
        utils.setUser(data.email);
        return "success";
      } else {
        return "forgetError";
      }
    } else {
      return "codeError";
    }
  },
};
const getters = {};
export default {
  state,
  mutations,
  actions,
  getters,
};
